<%@ page contentType="text/html;charset=utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
	<head>
		<title>空闲宿舍显示</title>
		<link rel="stylesheet"
			href="<%=request.getContextPath()%>/css/common.css" type="text/css" />
		<link rel="stylesheet"
			href="<%=request.getContextPath()%>/css/popup.css" type="text/css" />
		<link rel="stylesheet"
			href="<%=request.getContextPath()%>/css/style.css" type="text/css" />
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/sorttable.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/popup.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/apartmentViewAction.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/studentInDormitoryInfoViewAction.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/engine.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/util.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/jquery-latest.pack.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/noConflictOfJquery.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/forCSS.js'></script>
		<script type='text/javascript'>
			$j(function(){
				tbCSS();
			})
		</script>
		<script type="text/javascript">
			//全局变量
				var stuCache={};
				var inWhichDorm; //记录点击公寓时，该公寓的displayname，方便知道现实的学生是哪个公寓的
				setLoadingGif("http://localhost/dms/images/loading.gif");
				var DMS_ROOT = '<%=request.getContextPath()%>';
				
				/**
				* 给apart select框赋值的
				*/
				var gaptInfo=""; //这个gaptInfo是全局变量 
				
			function setApartList() {
					 apartmentViewAction.getAllApartInfo(mycallback);
				}
				
				var mycallback = function setList(aptValue)//回调函数
				{
						gaptInfo =aptValue;
						apartamount = gaptInfo.length; //给公寓总条数赋值
						var s = $("aptName");
					 	DWRUtil.removeAllOptions(s); 
						s.options[0] = new Option("请选择公寓",'0');
					for ( var i = 1; i < aptValue.length+1; i++) {
						var opt = new Option(aptValue[i-1].apartmentname,aptValue[i-1].apartmentid);
						s.options[i] = opt;
					}
					//将上次的查询条件传递过来
					var aptid = '<% out.print((null == request.getParameter("apartmentid"))?"":request.getParameter("apartmentid"));%>';
					for (var a = 0 ;a< $("aptName").options.length;a++){
						if( aptid== $("aptName").options[a].value){
							$("aptName").options[a].selected = 'selected';
						}
						
					}
					
					DWREngine.setAsync(false);  
					selectChange();
					DWREngine.setAsync(true); 
					var thefloorname = '<% out.print((null == request.getParameter("dormitoryfloorno"))?"":request.getParameter("dormitoryfloorno"));%>';
					for(var a = 0 ;a< $("floorName").options.length;a++){
						if( thefloorname == $("floorName").options[a].value){
							$("floorName").options[a].selected = 'selected';
						}
					}
					
					$("dormName").value = '<% out.print((null == request.getParameter("dormitoryname"))?"":request.getParameter("dormitoryname"));%>';
				}
				
				/**
				* 公寓select框change函数
				*/
				function selectChange(){
				apartmentid = $("aptName").options[$("aptName").selectedIndex].value; //给apartmentid赋值
						//取到了对应apartmentid的楼层数目
						var aprt_floorno;
						var aprt_name;					
						
						for(var m = 0; m<apartamount;m++){
							if(gaptInfo[m].apartmentid ==apartmentid){
							aprt_floorno = gaptInfo[m].apartmentfloornum;
							aprt_name = gaptInfo[m].apartmentname;
							
							break;
							}
						}
						var sf = $("floorName");
						DWRUtil.removeAllOptions(sf);  
						sf.options[0] = new Option("请选择楼层",'0');
						if(aprt_name == "七号楼"){
						for ( var j = 1; j < (parseInt(aprt_floorno)-1); j++) {
							var optt = new Option((j+2)+"层",(j+2));
							sf.options[j] = optt;
						}
						}
						else if(aprt_name == "三号楼"){
						for ( var j = 1; j < (parseInt(aprt_floorno)); j++) {
							var optt = new Option((j+1)+"层",(j+1));
							sf.options[j] = optt;
						}
						}
						else{
						for ( var j = 1; j < (parseInt(aprt_floorno)+1); j++) {
							var optt = new Option(j+"层",j);
							sf.options[j] = optt;
						}
						
						}
				}
				
		function onsubmit(){
			var   ops=$("aptName").options; 
			var 	a1 =ops[$("aptName").selectedIndex].text; //a1是公寓名
			var 	a11 =ops[$("aptName").selectedIndex].value; //a11是index值
			 //alert(a1==0) 
			 if(a11==0){
					alert("请选择一个公寓");
					return "1";
			}
			 var  opss=$("floorName").options; 
			 var f1 = opss[$("floorName").selectedIndex].value;
			var d1 = $("dormName").value;
			 
			if(a11==0&&f1==0){
				alert("请至少选择公寓名，或者公寓和楼层项");
				return "1";
			}
			 if((a11!="")&&f1==0&&(d1=="")){
				 return DMS_ROOT+"/aptmgr/listDormitory.action?apartmentid="+a11; //直接返回宿舍列表，不要单个公寓列表
				//return DMS_ROOT+"/aptmgr/listByAptId.action?apartmentid="+a11;
			}else{
				return DMS_ROOT+"/aptmgr/listSearchDorm.action?apartmentid="+a11+"&"+"dormitoryfloorno="+f1+"&"+"dormitoryname="+d1;  
				}
		}
		function onAvailsubmit(){
			var   ops=$("aptName").options; 
			var 	a1 =ops[$("aptName").selectedIndex].text; //a1是公寓名
			var 	a11 =ops[$("aptName").selectedIndex].value; //a11是index值
			 if(a11==0){
					alert("请选择一个公寓");
					return "1";
			 }
			var  opss=$("floorName").options; 
			var f1 = opss[$("floorName").selectedIndex].value;
			if(f1==0){
				//alert("请选择一个楼层!");
				return DMS_ROOT+"/aptmgr/listSearchDormStatus.action?apartmentid="+a11+"&"+"dormitoryfloorno="+f1;
			}
			return DMS_ROOT+"/aptmgr/listSearchDormStatus.action?apartmentid="+a11+"&"+"dormitoryfloorno="+f1;
		}
		
		
		function onActionSubmit(){
			if(onsubmit()=="1"){
				return;
			}
			window.location.href=onsubmit(); 
		}
		
		function onSelectAvailActionSubmit(){
			if(onAvailsubmit()=="1"){
				return;
			}
			window.location.href=onAvailsubmit(); 
		}

// 点击宿舍查看入住学生
function showstudentbydormitoryid(dormitoryidandname){
	var dormitoryid = dormitoryidandname.split("_")[0];
	inWhichDorm = dormitoryidandname.split("_")[1]; //全局变量赋值 
	studentInDormitoryInfoViewAction.listStudentInfoInSpecDorm(dormitoryid,showstudentcallback);
}
var showstudentcallback = function showstudentcb(showstulist){
	if($('stuinfolistdiv').style.visibility == 'hidden'){
		$('stuinfolistdiv').style.visibility = 'visible';
	}
	if(showstulist==null){ //未入住学生的宿舍给予提示
		if($('stuinfolistdiv').style.visibility == 'visible'){
			$('stuinfolistdiv').style.visibility = 'hidden';
		}
		if($('student_basic_info_search').style.visibility == 'visible'){
			$('student_basic_info_search').style.visibility = 'hidden';
		}
		if($('div_basicInfo').style.display == ""){
			$('div_basicInfo').style.display = "none";
		}
		if($('hr_id').style.display == ""){
			$('hr_id').style.display = "none";
		}
	alert("该宿舍暂未入住学生！");
	return;
}

	DWRUtil.removeAllRows('ttb', { filter:function(tr) {
	      return (tr.id != "pattern");
		    }});
	var st,id;
	 for (var i =0; i < showstulist.length ; i++) {
		 st = showstulist[i];
		 id = st[1];
		 dwr.util.cloneNode("pattern", { idSuffix:id });
	     dwr.util.setValue("tablestudentname"+id, st[2]);
	     dwr.util.setValue("tablestudentgender"+id, st[8]);
	     dwr.util.setValue("tablestudentno"+id, st[1]);
	     if(typeof(st[6])=="object"){
		 dwr.util.setValue("tablestudentclass"+id,"");  
		 }else{
	 	 dwr.util.setValue("tablestudentclass"+id,st[6]);  
		 } 
		 if(typeof(st[35])=="object"){
		 dwr.util.setValue("tablestudentcollegeinfo"+id,"");  
		 }else{
	 	 dwr.util.setValue("tablestudentcollegeinfo"+id,st[35]);  
		 }
		 if(typeof(st[36])=="object"){
		 dwr.util.setValue("tablestudentmajorinfo"+id,"");  
		 }else{
	 	 dwr.util.setValue("tablestudentmajorinfo"+id,st[36]);  
		 }
	     dwr.util.setValue("cbx" + id, st[0]);
	 	 $("pattern" + id).style.display= "";
	 	 stuCache[id] = st;
	   }
	   var str = showstulist[0];
	   showinfo("cbx"+str[1]);
	   tbCSS();
}

function showinfo(eleid){
var student_number = eleid.substring(3);
$('student_info').value = student_number;
stu_BasicInfo();
$('hr_id').style.display = "";
$('div_basicInfo').style.display = "";
$('student_basic_info_search').style.display = "none";
}

</script>

	</head>
	<body onLoad="javascript:setApartList()"
		style="margin: 0px; padding: 0px">
		<div id="page_container">
			<div class="divground">
				<table width="100%" border="0" cellspacing="1" cellpadding="0">
					<tr>
						<td height="49" bgcolor="ECECEC">
							<table width="93%" border="0" align="center" cellpadding="0"
								cellspacing="0">
								<tr>
									<td width="86%">
										<select name="aptName" id="aptName" style="width: 120"
											onchange="javascript:selectChange();">
										</select>
										&nbsp;
										<select name="floorName" id="floorName" onchange="onActionSubmit();" style="width: 120">
										</select>
										&nbsp;宿舍号
										<input type="text" name="dormName" id="dormName" size="15"
											value="" class="Text" style="width: 80px;">
									</td>
									<td width="4%">
										<a href="javascript:onActionSubmit();"><img
												src="<%=request.getContextPath()%>/images/ss.gif"> </a>
									</td>
									<td width="4%">
										<a href="javascript:onSelectAvailActionSubmit();"><img
												src="<%=request.getContextPath()%>/images/kx.gif"> </a>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>


				<!--  循环给出空闲宿舍的图标-->
				<s:iterator value="myDormInfoList" id="id" status="st">
					<div class="dormitory">
						<!-- [0]表示的宿舍id -->
						<!-- [1]表示的已经入住人数 -->
						<!-- [2]表示的宿舍显示名字 -->
						<!-- [3]表示的房型 -->
						<!-- [4]表示的男女 -->
						<!-- [5]表示的宿舍名字 -->
						<div class="dormiroyimg">
							<img
								src="<%=request.getContextPath()%>/images/dormpic/<s:property value="myDormInfoList[#st.index][4]" /><s:property value="myDormInfoList[#st.index][3]" /><s:property value="myDormInfoList[#st.index][1]" />.jpg"
								id="<s:property value="myDormInfoList[#st.index][0]" />_<s:property value="myDormInfoList[#st.index][2]" />"
								onclick='javascript:showstudentbydormitoryid(this.id);' />
							<!-- sex roomtype instudent -->
						</div>
						<div class="dormitoryinfo">
							<s:property value="myDormInfoList[#st.index][5]" />
						</div>
					</div>
				</s:iterator>
				<br />
				<div class="navigator">
					<table>
						<tr>
							<td colspan="9">
								共
								<s:property value="totalRows" />
								条&nbsp; 第
								<s:property value="currentPage" />
								页&nbsp; 共
								<s:property value="pager.getTotalPages()" />
								页&nbsp;
								<a
									href="<s:url value="/aptmgr/listDormitory.action">
    			<s:param name="currentPage" value="currentPage"/>
    			<s:param name="pagerMethod" value="'first'"/>
    			
    		</s:url>">首页</a>
								<a
									href="<s:url value="/aptmgr/listSearchDormStatus.action">
    			<s:param name="currentPage" value="currentPage"/>
    			<s:param name="pagerMethod" value="'previous'"/>
    		</s:url>">上一页</a>
								<a
									href="<s:url value="/aptmgr/listSearchDormStatus.action">
    			<s:param name="currentPage" value="currentPage"/>
    			<s:param name="pagerMethod" value="'next'"/>
    		</s:url>">下一页</a>
								<a
									href="<s:url value="/aptmgr/listSearchDormStatus.action">
    			<s:param name="currentPage" value="currentPage"/>
    			<s:param name="pagerMethod" value="'last'"/>
    		</s:url>">尾页</a>
							</td>
						</tr>
					</table>
					<hr style="width: 95%" />
					<div id="dormview_studentinfo">
						<div id="stuinfolistdiv" style="visibility: hidden;">
							<table id="stuinfolistdiv_table"
								class="sortable table_common table_list_style"
								rowclass="row_odd,row_even" style="width: 600px;">
								<tr>
										<th style="width: 10%">学号</th>
										<th style="width: 10%">姓名</th>
										<th style="width: 10%">性别</th>
										<th style="width: 20%">班级</th>
										<th style="width: 25%">学院</th>
										<th style="width: 25%">专业</th>
								</tr>
								<tbody id="ttb">
									<!-- 隐藏的项目 onclick="test(this.id)-->

									<tr id="pattern" style="display: none;"
										onclick="javascript:showinfo(this.id.substr(4))">
										<td>
											<div id="tablestudentno"></div>
										</td>
										<td height="18">
											<div id="tablestudentname"></div>
										</td>
										<td>
											<div id="tablestudentgender"></div>
										</td>
										<td height="18">
											<div id="tablestudentclass"></div>
										</td>
										<td>
											<div id="tablestudentcollegeinfo"></div>
										</td>
										<td>
											<div id="tablestudentmajorinfo"></div>
										</td>
										<!-- 
										<td>
											<input id="cbx" type="image"
												src="<%=request.getContextPath()%>/images/stu_info.png"
												value="Submit" alt="Submit"
												onClick="javascript:showinfo(this.id)"
												style="border-width: 0px;" />
										</td>
										 -->
									</tr>
								</tbody>
							</table>
						</div>
						<hr style="display: none; width: 95%" id="hr_id" />
						<!-- 学生基本信息tab页显示开始 -->
						<div style="display: none;" id="div_basicInfo">
							<jsp:include page="/student/basicstudentinfo.jsp"></jsp:include>
						</div>
						<!-- 学生基本信息tab页显示结束 -->
					</div>
				</div>
			</div>
		</div>
	</body>
</html>
